<script setup>
// TODO: 编辑
import { ref } from 'vue'
// 弹框开关
const dialogVisible = ref(false)
const formdata = ref({
  id: '',
  name: '',
  place: ''
})
import axios from 'axios'
const emit = defineEmits(['edit'])
const open = (row) => {
  dialogVisible.value = true
  console.log(row)
  formdata.value.name = row.name
  formdata.value.place = row.place
  formdata.value.id = row.id
}
defineExpose({ open })
const edit = async () => {
  console.log(formdata.value.id)
  await axios.patch(`/edit/${formdata.value.id}`,formdata.value)
  dialogVisible.value = false
  emit('edit')
}
</script>

<template>
  <el-dialog v-model="dialogVisible" title="编辑" width="400px">
    <el-form label-width="50px">
      <el-form-item label="姓名">
        <el-input v-model="formdata.name" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="籍贯">
        <el-input v-model="formdata.place" placeholder="请输入籍贯" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="edit()">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.el-input {
  width: 290px;
}
</style>
